<?php
namespace app\admin\controller;

use app\admin\controller\BaseController;

/**
 * 后台首页
 * Class Index
 */
class IndexController extends BaseController {

	protected function _initialize() {
		parent::_initialize();
	}

	/**
	 * 首页
	 * @return mixed
	 */
	public function index() {
		$data['mems']=db("member")->count("id");
		$data['agents']=db('agent')->count("id");
		$data['mfp']=db('ticketlogs')->where("type",2)->where('status',2)->count("id");
		$data['dzp']=db('ticketlogs')->where("type",1)->where('status',2)->count("id");
		$this->assign('data',$data);
		// 平台会员
		//会员总数
		return $this->fetch();
	}

	/**
	 * 清除缓存
	 */
	public function clear() {
		if (delete_dir_file(CACHE_PATH) || delete_dir_file(TEMP_PATH)) {
			$this->success('清除缓存成功');
		} else {
			$this->error('清除缓存失败');
		}
	}

	/**
	 * 更新密码
	 * @param $id
	 * @param $group_id
	 */
	public function update() {
		if ($this->request->isPost()) {
			$data = $this->request->post();
			if (empty($data['old_pwd'])) {
				$this->error('请输入旧密码');
			}
			if (empty($data['login_pwd']) || empty($data['login_pwd2'])) {
				$this->error('请输入新密码');
			}
			if ($data['login_pwd'] != $data['login_pwd2']) {
				$this->error('二次密码输入不一致');
			}
			if (md5_salt($data['old_pwd']) != session('ADMIN.login_pwd')) {
				$this->error('旧密码错误');
			}
			$data2['login_pwd'] = md5_salt($data['login_pwd']);
			$data2['id'] = session('ADMIN.id');
			if (db('user')->update($data2) !== false) {
				$this->success('更新成功');
			} else {
				$this->error('更新失败');
			}
		} else {
			return $this->fetch('update', array('user' => session('ADMIN')));
		}
	}

}
